<template>
  <a-card :bordered="false">
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新建分项标准</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <template>
        <span style="float:right;">
          <a @click="searchQuery()"><a-icon type="sync" />刷新</a>
          <a-divider type="vertical" />
          <a-button v-print="'#datatable'" ghost type="primary">打印</a-button>
        </span>
      </template>
      <span style='color:#0db869;'>提示：在增加评分标准项的时候可以【先复制->再修改】的方式增加</span>
      <span style='color:#d20d0d;'>&nbsp;&nbsp;【先创建总分的评分标准-->再创建题型的评分标准】请先确保已存在总分评分标准</span>
      <!-- 高级查询区域 -->
<!--      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
    </div>
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <!-- 分项评分标准 -->
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="proId"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a-button @click="handleCopyAddItem(record)" type="primary">复制</a-button>
          <a @click="handleEditItem(record)" style='margin-left: 20px;'>编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetailItem(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDeleteItem(record.proId)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
        <!-- 渲染某一列 -->
        <span slot="proStandardSubName" slot-scope="proStandardSubName">
          <a-tag style='background-color: rgb(37,189,231);color: #ffffff;font-size: 14px;padding: 0px 10px 0px 10px;'>
            {{ proStandardSubName }}
          </a-tag>
        </span>
      </a-table>
    </div>

    <!-- 新增分项标准 -->
    <template>
      <j-modal
        :title="title"
        :width="width"
        :visible="visible"
        switchFullscreen
        @ok="handleOk"
        :okButtonProps="{ class:{'jee-hidden': disableAddSubmit} }"
        @cancel="handleCancel"
        cancelText="关闭">
        <call-ach-standard-item-project-item-form ref='modalForm' @ok="submitCallback" :disabled="disableAddSubmit"></call-ach-standard-item-project-item-form>
      </j-modal>
    </template>

    <!-- 复制式新增分项标准 -->
    <template>
      <j-modal
        :title="modalCopyFormTitle"
        :width="width"
        :visible="copyAddVisible"
        switchFullscreen
        @ok="handleCopyItemOk"
        :okButtonProps="{ class:{'jee-hidden': copyFormDisableSubmit} }"
        @cancel="handleCopyItemCancel"
        cancelText="关闭">
        <form-copy-add-standard-item-form ref="modalCopyForm" @ok="submitCopyCallback" :disabled="copyFormDisableSubmit"></form-copy-add-standard-item-form>
      </j-modal>
    </template>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { deleteAction, getAction } from '@api/manage'
import CallAchStandardItemProjectItemForm from '@views/smart_school/achexaminationpaper/form/formModules/CallAchStandardItemProjectItemForm'
import FormCopyAddStandardItemForm from '@views/smart_school/achexaminationpaper/form/formModules/FormCopyAddStandardItemForm'

export default {
  name: 'CallAchExamPapProjectItemStandard',
  mixins:[JeecgListMixin, mixinDevice],
  components: {
    CallAchStandardItemProjectItemForm,
    FormCopyAddStandardItemForm,
  },
  data () {
    return {
      //下方分项评分标准
      columns:[
        {
          title: '#',
          dataIndex: '',
          key:'rowIndex',
          width:60,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },
        {
          title:'评分标准',
          align:"center",
          dataIndex: 'achievementStandardName'
        },
        // {
        //   title:'所属试卷名称',
        //   align:"center",
        //   dataIndex: 'examinationPaperName'
        // },
        // {
        //   title:'试卷项目编码',
        //   align:"center",
        //   dataIndex: 'exaPapProItemCode'
        // },

        {
          title:'试卷项目名称',
          align:"center",
          dataIndex: 'exaPapProItemName'
        },
        {
          title:'项目分段名称',
          align:"center",
          dataIndex: 'proStandItemName'
        },
        {
          title:'评分参数（"["包含 ")"不包含）',
          align:"left",
          scopedSlots: { customRender: 'proStandardSubName' },
          width:300,
          dataIndex: 'proStandardSubName'
        },

        {
          title:'标准类型',
          align:"center",
          dataIndex: 'achievementStandardTtype_dictText'
        },
        // {
        //   title:'标准用途',
        //   align:"center",
        //   dataIndex: 'achievementStandardPurpose_dictText'
        // },
        {
          title:'用途类型',
          align:"center",
          dataIndex: 'achiStandPurposeType_dictText'
        },
        {
          title:'项目序号',
          align:"center",
          sorter: true,
          dataIndex: 'standItemOrder'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align:"center",
          fixed:"right",
          width:147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/achexampaperprojectitem/achExamPaperProjectItem/getAchExamProjectItemStandard",
        delete: "/achachievestandarditem/achAchieveStandardItem/delete",//删除标准明细（分项）
        deleteBatch: "/achachievestandarditem/achAchieveStandardItem/deleteBatch",
      },
      loading:false,
      /* table选中keys*/
      selectedRowKeys: [],
      /* table选中records*/
      selectionRows: [],
      //下方 项目切换的拼接评分标准数据
      dataSource: [],
      dictOptions:{},
      superFieldList:[],

      /* 分页参数 */
      ipagination:{
        current: 1,
        pageSize: 30,
        pageSizeOptions: ['10', '20', '30','50','100','500','1000'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },

      queryParam: {
        mainId: null,//试卷id
      },
      paperModel: {
        paperId: null,
        subjectId: null,
      },
      //modal 新增分项标准
      title:'',
      width:800,
      visible: false,
      disableAddSubmit: false,
      //modal 复制分项标准
      modalCopyFormTitle:'',
      copyAddVisible: false,
      copyFormDisableSubmit: false
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    initDictConfig(){
    },

    loadData(arg) {
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      //update-begin--Author:kangxiaolin  Date:20190905 for：[442]主子表分开维护，生成的代码子表的分页改为真实的分页--------------------
      var params = this.getQueryParams();
      getAction(this.url.list, {examinationPaperId: params.mainId, pageNo : this.ipagination.current,
        pageSize :this.ipagination.pageSize}).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records;
          this.ipagination.total = res.result.total;
        } else {
          this.dataSource = null;
        }
      })

    },

    getOrderMain(record) {
      this.queryParam.mainId = record.id;
      this.paperModel = record
      this.loadData(1);
    },

    //新增分项标准 ================
    handleAdd: function (record) {
      //判断是否选择了一项
      if (this.queryParam.mainId === null){
        alert("请先选择一条上级标准")
        return
      }
      this.visible = true
      this.$nextTick(()=>{
        this.$refs.modalForm.add(this.paperModel);
        this.title = "添加分项标准";
        this.$refs.modalForm.disableAddSubmit = false;
      })
    },
    handleOk(){
      this.$refs.modalForm.submitForm();
    },
    submitCallback(){
      this.$emit('ok');
      this.visible = false;
    },
    handleCancel(){
      this.visible=false
    },

    //复制标准项====复制式新增标准(statusKey = 1)=================
    recordUtil(recordData){
      recordData.id = recordData.proId; // 分段评分标准明细ID
      recordData.achievementStandardId = recordData.proAchievementStandardId;
      recordData.subjectId = recordData.proSubjectId;
      recordData.exaPapProItemCode = recordData.proExaPapProItemCode;
      recordData.standItemCode = recordData.proStandItemCode;
      recordData.standItemName = recordData.proStandItemName; // 分项评分标准分段名称
      recordData.standItemAliasname = recordData.proStandItemAliasname;
      recordData.standItemLowestScore = recordData.proStandItemLowestScore;
      recordData.standItemHighestScore = recordData.proStandItemHighestScore;
      recordData.standItemLowestRate = recordData.proStandItemLowestRate;
      recordData.standItemHighestRate = recordData.proStandItemHighestRate;
      recordData.standItemActualScore = recordData.proStandItemActualScore;
      recordData.standItSpecialRestrictions = recordData.proStandItSpecialRestrictions;
      recordData.sitemSpecRestMinvalue = recordData.proSitemSpecRestMinvalue;
      recordData.sitemSpecRestMaxvalue = recordData.proSitemSpecRestMaxvalue;
      recordData.standItemOrder = recordData.proStandItemOrder;
      recordData.standItemWeightCoefficient = recordData.proStandItemWeightCoefficient;
      recordData.standItemFatherId = recordData.proStandItemFatherId;
      recordData.izOpen = recordData.proIzOpen;
      recordData.sysOrgCode = recordData.proSysOrgCode;
      recordData.tenantId = recordData.proTenantId;
      recordData.delFlag = recordData.proDelFlag;
      recordData.createBy = recordData.proCreateBy;
      recordData.createTime = recordData.proCreateTime;
      recordData.updateBy = recordData.proUpdateBy;
      recordData.updateTime = recordData.proUpdateTime;
      return recordData;
    },
    handleCopyAddItem: function (record) {
      this.recordUtil(record)//字段处理
      this.copyAddVisible = true
      this.copyFormDisableSubmit = false;
      this.$nextTick(()=>{
        record.statusKey = 1;//复制式新增(1) ,编辑(2)
        this.$refs.modalCopyForm.add(record);
        this.modalCopyFormTitle = "复制总分标准";
      })
    },
    //编辑标准项====编辑标准(statusKey = 2)=================
    handleEditItem: function (record) {
      this.recordUtil(record)//字段处理
      this.copyAddVisible = true
      this.copyFormDisableSubmit = false;
      this.$nextTick(()=>{
        record.statusKey = 2;//复制式新增(1) ,编辑(2)
        this.$refs.modalCopyForm.edit(record);
        this.modalCopyFormTitle = "编辑总分标准";
      })
    },
    //提交
    handleCopyItemOk(){
      this.$refs.modalCopyForm.submitForm();
    },
    submitCopyCallback(){
      this.$emit('ok');
      this.copyAddVisible = false;
    },
    handleCopyItemCancel(){
      this.copyAddVisible=false
    },

    //查看详情
    handleDetailItem:function(record){
      this.recordUtil(record)//字段处理
      this.copyAddVisible = true
      this.copyFormDisableSubmit = true;
      this.$nextTick(()=>{
        record.statusKey = 2;//复制式新增(1) ,编辑(2),详情（3）
        this.$refs.modalCopyForm.edit(record);
        this.modalCopyFormTitle = "详情";
      })
    },
    //通过ID删除
    handleDeleteItem(proId){
      if(!this.url.delete){
        this.$message.error("请设置url.delete属性!")
        return
      }
      let params = {
        id: proId
      }
      console.log("proId==== " + proId)
      deleteAction(this.url.delete, params).then((res) => {
        if (res.success) {
          this.$message.success(res.message);
          // this.loadData();
        } else {
          this.$message.warning(res.message);
        }
      });
    },

  }
}
</script>

<style scoped>
@import '~@assets/less/common.less';
</style>